/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */

package xowl.interpreter;

/**
 *
 * @author Laurent WOUTERS
 */
public class Interpreter {
    private static final String[] libsInit = new String[] {
        "xerces/xercesImpl.jar",
        "xerces/serializer.jar"
    };
    private static final String[] libsJena = new String[] {
        "jena/jena-2.6.3.jar",
        "jena/arq-2.8.4.jar",
        "jena/slf4j-api-1.5.8.jar",
        "jena/slf4j-log4j12-1.5.8.jar",
        "jena/iri-0.8.jar",
        "jena/icu4j-3.4.4.jar" };
    private static final String[] libsOWLAPI = new String[] { "owlapi/owlapi-bin.jar" };
    private static final String[] libsPellet = new String[] {
        "aterm/aterm-java-1.6.jar",
        "jgrapht/jgrapht-jdk1.5.jar",
        "pellet/pellet-core.jar",
        "pellet/pellet-datatypes.jar",
        "pellet/pellet-el.jar",
        "pellet/pellet-owlapiv3.jar",
        "pellet/pellet-rules.jar" };
    private static final String[] libsPelletJena = new String[] { "pellet/pellet-jena.jar" };
    private static final String[] libsHermiT = new String[] { "hermit/HermiT.jar" };
    
    private static LibManager libManager;
    
    public static void config(xowl.utils.logging.Logger logger, String path) {
        libManager = new LibManager(logger, path);
        libManager.execute(libsInit);
    }
    public static void loadLibraries(String[] libs) { libManager.execute(libs); }
    
    public static Thread createThread(Repository repository) {
        xowl.interpreter.impl.BaseRepository repo = (xowl.interpreter.impl.BaseRepository)repository;
        xowl.interpreter.impl.AggregatedEvaluator eval = new xowl.interpreter.impl.AggregatedEvaluator(repo);
        for (xowl.interpreter.impl.Evaluator part : repo.getEvaluatorParts())
            eval.addPart(part);
        return new xowl.interpreter.impl.ThreadRunner(repo, eval);
    }
    
    public static Repository createRepositoryNative(xowl.utils.logging.Logger log) {
        return new xowl.interpreter.backends.mlm.MLMRepository(log);
    }
    public static Repository createRepositoryNativeRDF(xowl.utils.logging.Logger log) {
        return new xowl.interpreter.backends.rdf.SimpleRDFRepository(log);
    }
    public static Repository createRepositoryJena(xowl.utils.logging.Logger log, xowl.interpreter.backends.jena.ReasonerProvider provider) {
        libManager.execute(libsJena);
        return new xowl.interpreter.backends.jena.JenaRepository(log, provider);
    }
    public static Repository createRepositoryJenaPellet(xowl.utils.logging.Logger log) {
        libManager.execute(libsJena);
        libManager.execute(libsPellet);
        libManager.execute(libsPelletJena);
        xowl.interpreter.backends.jena.ReasonerProvider provider = new xowl.interpreter.backends.pellet.JenaReasoner();
        return new xowl.interpreter.backends.jena.JenaRepository(log, provider);
    }
}